From: Joey Hess Date: Tue, 16 Sep 2025 18:58:26 +0000 (-0400) Subject: annex.assistant.allowunlocked X-Git-Tag: archive/raspbian/10.20251029-1+rpi1~1^2~3^2~92 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=92c4a3441426e359dc8028175a22a54dae0c09be;p=git-annex.git annex.assistant.allowunlocked Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project --- diff --git a/Assistant/Threads/Committer.hs b/Assistant/Threads/Committer.hs index 6ffc9eb0e1..53663e8b5b 100644 --- a/Assistant/Threads/Committer.hs +++ b/Assistant/Threads/Committer.hs @@ -62,6 +62,11 @@ commitThread = namedThread "Committer" $ do fmap Seconds . annexDelayAdd <$> Annex.getGitConfig largefilematcher <- liftAnnex largeFilesMatcher annexdotfiles <- liftAnnex $ getGitConfigVal annexDotFiles + addunlockedmatcher <- liftAnnex $ + ifM (annexSupportUnlocked <$> Annex.getGitConfig) + ( Just <$> addUnlockedMatcher + , return Nothing + ) msg <- liftAnnex Command.Sync.commitMsg lockdowndir <- liftAnnex $ fromRepo gitAnnexTmpWatcherDir liftAnnex $ do @@ -70,7 +75,7 @@ commitThread = namedThread "Committer" $ do void $ liftIO $ tryIO $ removeDirectoryRecursive lockdowndir void $ createAnnexDirectory lockdowndir waitChangeTime $ \(changes, time) -> do - readychanges <- handleAdds lockdowndir havelsof largefilematcher annexdotfiles delayadd $ + readychanges <- handleAdds lockdowndir havelsof largefilematcher annexdotfiles addunlockedmatcher delayadd $ simplifyChanges changes if shouldCommit False time (length readychanges) readychanges then do @@ -275,8 +280,8 @@ commitStaged msg = do - Any pending adds that are not ready yet are put back into the ChangeChan, - where they will be retried later. -} -handleAdds :: OsPath -> Bool -> GetFileMatcher -> Bool -> Maybe Seconds -> [Change] -> Assistant [Change] -handleAdds lockdowndir havelsof largefilematcher annexdotfiles delayadd cs = returnWhen (null incomplete) $ do +handleAdds :: OsPath -> Bool -> GetFileMatcher -> Bool -> Maybe AddUnlockedMatcher -> Maybe Seconds -> [Change] -> Assistant [Change] +handleAdds lockdowndir havelsof largefilematcher annexdotfiles addunlockedmatcher delayadd cs = returnWhen (null incomplete) $ do let (pending, inprocess) = partition isPendingAddChange incomplete let lockdownconfig = LockDownConfig { lockingFile = False @@ -340,9 +345,9 @@ handleAdds lockdowndir havelsof largefilematcher annexdotfiles delayadd cs = ret Command.Add.addFile Command.Add.Small f =<< liftIO (R.getSymbolicLinkStatus (fromOsPath f)) - {- Avoid overhead of re-injesting a renamed unlocked file, by - - examining the other Changes to see if a removed file has the - - same InodeCache as the new file. If so, we can just update + {- When adding the file unlocked, avoid overhead of re-injesting a renamed + - unlocked file, by examining the other Changes to see if a removed + - file has the same InodeCache as the new file. If so, we can just update - bookkeeping, and stage the file in git. -} addannexed :: [Change] -> Assistant [Maybe Change] @@ -357,18 +362,36 @@ handleAdds lockdowndir havelsof largefilematcher annexdotfiles delayadd cs = ret , checkWritePerms = True } if M.null m - then forM toadd (addannexed' cfg) + then forM toadd $ \c -> do + mcache <- liftIO $ genInodeCache (changeFile c) delta + addunlocked <- checkaddunlocked c + addannexed' cfg c addunlocked mcache else forM toadd $ \c -> do mcache <- liftIO $ genInodeCache (changeFile c) delta - case mcache of - Nothing -> addannexed' cfg c - Just cache -> - case M.lookup (inodeCacheToKey ct cache) m of - Nothing -> addannexed' cfg c - Just k -> fastadd c k - - addannexed' :: LockDownConfig -> Change -> Assistant (Maybe Change) - addannexed' lockdownconfig change@(InProcessAddChange { lockedDown = ld }) = + ifM (checkaddunlocked c) + ( case mcache of + Nothing -> addannexed' cfg c True Nothing + Just cache -> + case M.lookup (inodeCacheToKey ct cache) m of + Nothing -> addannexed' cfg c True Nothing + Just k -> fastadd c k + , addannexed' cfg c False mcache + ) + + checkaddunlocked (InProcessAddChange { lockedDown = ld }) = + case addunlockedmatcher of + Just addunlockedmatcher' -> do + let mi = MatchingFile $ FileInfo + { contentFile = contentLocation (keySource ld) + , matchFile = keyFilename (keySource ld) + , matchKey = Nothing + } + liftAnnex $ addUnlocked addunlockedmatcher' mi True + Nothing -> return True + checkaddunlocked _ = return True + + addannexed' :: LockDownConfig -> Change -> Bool -> Maybe InodeCache -> Assistant (Maybe Change) + addannexed' lockdownconfig change@(InProcessAddChange { lockedDown = ld }) addunlocked mcache = catchDefaultIO Nothing <~> doadd where ks = keySource ld @@ -376,14 +399,14 @@ handleAdds lockdowndir havelsof largefilematcher annexdotfiles delayadd cs = ret (mkey, _mcache) <- liftAnnex $ do showStartMessage (StartMessage "add" (ActionItemOther (Just (QuotedPath (keyFilename ks)))) (SeekInput [])) ingest nullMeterUpdate (Just $ LockedDown lockdownconfig ks) Nothing - maybe (failedingest change) (done change $ keyFilename ks) mkey - addannexed' _ _ = return Nothing + maybe (failedingest change) (done change addunlocked mcache $ keyFilename ks) mkey + addannexed' _ _ _ _ = return Nothing fastadd :: Change -> Key -> Assistant (Maybe Change) fastadd change key = do let source = keySource $ lockedDown change liftAnnex $ finishIngestUnlocked key source - done change (keyFilename source) key + done change True Nothing (keyFilename source) key removedKeysMap :: InodeComparisonType -> [Change] -> Annex (M.Map InodeCacheKey Key) removedKeysMap ct l = do @@ -399,11 +422,14 @@ handleAdds lockdowndir havelsof largefilematcher annexdotfiles delayadd cs = ret liftAnnex showEndFail return Nothing - done change file key = liftAnnex $ do + done change addunlocked mcache file key = liftAnnex $ do logStatus NoLiveUpdate key InfoPresent - mode <- liftIO $ catchMaybeIO $ - fileMode <$> R.getFileStatus (fromOsPath file) - stagePointerFile file mode =<< hashPointerFile key + if addunlocked + then do + mode <- liftIO $ catchMaybeIO $ + fileMode <$> R.getFileStatus (fromOsPath file) + stagePointerFile file mode =<< hashPointerFile key + else addSymlink file key mcache showEndOk return $ Just $ finishedChange change key diff --git a/CHANGELOG b/CHANGELOG index 740253853a..72e4a419f5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ git-annex (10.20250829) UNRELEASED; urgency=medium * Removed support for building with cryptonite, use crypton. * p2phttp: Fix a hang that could occur when used with --directory, and a repository in the repository got removed. + * Added annex.assistant.allowunlocked config. -- Joey Hess Fri, 29 Aug 2025 12:34:06 -0400 diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs index 35b07a50a3..156b88c32c 100644 --- a/Types/GitConfig.hs +++ b/Types/GitConfig.hs @@ -157,6 +157,7 @@ data GitConfig = GitConfig , annexSkipUnknown :: Bool , annexAdjustedBranchRefresh :: Integer , annexSupportUnlocked :: Bool + , annexAssistantAllowUnlocked :: Bool , coreSymlinks :: Bool , coreSharedRepository :: SharedRepository , coreQuotePath :: QuotePath @@ -281,6 +282,7 @@ extractGitConfig configsource r = GitConfig (if getbool "adjustedbranchrefresh" False then 1 else 0) (getmayberead (annexConfig "adjustedbranchrefresh")) , annexSupportUnlocked = getbool (annexConfig "supportunlocked") True + , annexAssistantAllowUnlocked = getbool (annexConfig "assistant.allowunlocked") False , coreSymlinks = getbool "core.symlinks" True , coreSharedRepository = getSharedRepository r , coreQuotePath = QuotePath (getbool "core.quotepath" True) diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index 6b668f69b5..4f633d7f0e 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -1044,13 +1044,23 @@ repository, using [[git-annex-config]]. See its man page for a list.) To configure a default annex.addunlocked for all clones of the repository, this can be set in [[git-annex-config]](1). - (Using `git add` always adds files in unlocked form and it is not - affected by this setting.) + Using `git add` always adds files in unlocked form and it is not + affected by this setting. The assistant defaults to adding all files + unlocked, unless `annex.assistant.allowunlocked` is set. When a repository has core.symlinks set to false, or has an adjusted unlocked branch checked out, this setting is ignored, and files are always added to the repository in unlocked form. +* `annex.assistant.allowunlocked` + + The `git-annex assistant` defaults to adding all files unlocked, so that + files can be modified without the user needing to do anything to unlock + them. + + If this is set to `true` then it will instead use the `annex.addunlocked` + configuration to decide which files to add unlocked. + * `annex.numcopies` This is a deprecated setting. You should instead use the diff --git a/doc/todo/allow_configuring_assistant_to_add_files_locked.mdwn b/doc/todo/allow_configuring_assistant_to_add_files_locked.mdwn index ed0a60d5a4..2232354158 100644 --- a/doc/todo/allow_configuring_assistant_to_add_files_locked.mdwn +++ b/doc/todo/allow_configuring_assistant_to_add_files_locked.mdwn @@ -4,11 +4,10 @@ configured to add them locked. There are good reasons for that different behavior to be the default, but it would be worth having a config to override that. -Eg, when annex.assistant.honor.addunlocked is set, honor the -annex.addunlocked configuration, which defaults to adding files locked. -Or perhaps a better name would be annex.assistant.allowaddlocked. - See here for some motivating use cases [[!tag projects/repronim]] + +> [[done]], git config annex.assistant.allowunlocked to true, +> and then configure annex.addunlocked as desired. --[[Joey]]